#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "wayPoint.h"
#include"TowerPosition.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    addWayPoint1();//增加航点函数的调用
    loadTowerPosition1();
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::addWayPoint1()
{
    wayPoint* waypoint1 = new wayPoint(QPoint(698, 206));
    m_wayPointList.push_back(waypoint1);

    wayPoint* waypoint2 = new wayPoint(QPoint(514, 203));
    waypoint1->setNextWayPoint(waypoint2);
    m_wayPointList.push_back(waypoint2);

    wayPoint* waypoint3 = new wayPoint(QPoint(510, 95));
    waypoint2->setNextWayPoint(waypoint3);
    m_wayPointList.push_back(waypoint3);

    wayPoint* waypoint4 = new wayPoint(QPoint(381, 95));
    waypoint3->setNextWayPoint(waypoint4);
    m_wayPointList.push_back(waypoint4);

    wayPoint* waypoint5 = new wayPoint(QPoint(354, 196));
    waypoint4->setNextWayPoint(waypoint5);
    m_wayPointList.push_back(waypoint5);

    wayPoint* waypoint6 = new wayPoint(QPoint(185, 227));
    waypoint5->setNextWayPoint(waypoint6);
    m_wayPointList.push_back(waypoint6);

    wayPoint* waypoint7 = new wayPoint(QPoint(189, 328));
    waypoint6->setNextWayPoint(waypoint7);
    m_wayPointList.push_back(waypoint7);

    wayPoint* waypoint8 = new wayPoint(QPoint(436, 323));
    waypoint7->setNextWayPoint(waypoint8);
    m_wayPointList.push_back(waypoint8);

    wayPoint* waypoint9 = new wayPoint(QPoint(422, 429));
    waypoint8->setNextWayPoint(waypoint9);
    m_wayPointList.push_back(waypoint9);

    wayPoint* waypoint10 = new wayPoint(QPoint(316, 455));
    waypoint9->setNextWayPoint(waypoint10);
    m_wayPointList.push_back(waypoint10);

    wayPoint* waypoint11 = new wayPoint(QPoint(312, 597));
    waypoint10->setNextWayPoint(waypoint11);
    m_wayPointList.push_back(waypoint11);
}
void MainWindow::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QString path(":/images/background1.bmp");//path是你图片的路径

    painter.drawPixmap(0,0,700,600,path);
    foreach(const wayPoint * waypoint,m_wayPointList)
            waypoint->draw(&painter);
    foreach(const TowerPosition towerposition,m_towerPositionList)
           towerposition.draw(&painter);
    //drawPixmap的前四个参数代表的分别是，图片左上角的横坐标，图片左上角的纵坐标，图片的width，图片的height。我们一般把width和height，与图片的真实大小匹配起来
}


void MainWindow::loadTowerPosition1()
{
    //这里和找航点是一样的，制作者需要自己不断尝试
    //找到比较合适的防御塔坑点
    QPoint pos[]=
    {
        QPoint(417,129),
        QPoint(74,240),
        QPoint(318,257),
        QPoint(277,143),
        QPoint(224,257),
        QPoint(353,363),
        QPoint(255,384),
        QPoint(506,372),
        QPoint(467,447),
        QPoint(358,484),
    };
    int len=sizeof(pos)/sizeof(pos[0]);
    for(int i=0;i<len;i++)
    {
        m_towerPositionList.push_back(pos[i]);
    }
}

